package com.wind.taobao.api.jianghu.convert
{
	import com.wind.taobao.api.jianghu.model.Poke;
	import com.wind.taobao.core.util.TaobaoConstants;

	import mx.collections.ArrayCollection;


	/**
	 * Poke 转换器
	 * @author fxy
	 *
	 */
	public class PokeConvert
	{
		/**
		 * 转换Poke集合
		 */
		public static function convertPokes(value:Object, type:String="json"):ArrayCollection
		{
			var pokes:ArrayCollection=new ArrayCollection();
			if (value != null)
			{
				if (type == TaobaoConstants.JSON)
				{
					if ((value as Array).length > 0)
					{
						for (var i:uint=0; i < (value as Array).length; i++)
						{
							pokes.addItem(convertPoke((value as Array)[i]));
						}
					}
				}
				else
				{
					//TODO
				}
			}
			return pokes;
		}

		/**
		 * 转换Poke
		 */
		public static function convertPoke(value:Object, type:String="json"):Poke
		{
			var poke:Poke=new Poke();
			if (value == null)
				return poke;
			if (type == TaobaoConstants.XML)
			{
				poke=convertXMLToPoke(XML(value), poke);
			}
			else
			{
				poke=convertJSONToPoke(value, poke);
			}
			return poke;
		}

		/**
		 * JSON转换为Poke
		 */
		private static function convertJSONToPoke(json:Object, poke:Poke):Poke
		{
			if (json.hasOwnProperty(TaobaoConstants.POKE_INFO_ID))
			{
				poke.poke_info_id=json[TaobaoConstants.POKE_INFO_ID];
			}
			if (json.hasOwnProperty(TaobaoConstants.POKE_NAME))
			{
				poke.poke_name=json[TaobaoConstants.POKE_NAME];
			}
			if (json.hasOwnProperty(TaobaoConstants.POKE_IMG_PATH))
			{
				poke.poke_img_path=json[TaobaoConstants.POKE_IMG_PATH];
			}
			return poke;
		}

		/**
		 * XML转换为Poke
		 */
		private static function convertXMLToPoke(value:XML, poke:Poke):Poke
		{
			return poke;
		}

	}
}